<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>OptionsPricing: PIDEStatic1D.py Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">OptionsPricing
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="dir_ecbb14687e1bcdda1258b79279264b64.html">models</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">PIDEStatic1D.py</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="stringliteral">&quot;&quot;&quot; Integro differential equation a*u_xx + b* u_x + c*u + l(conv(u, p) - u) &quot;&quot;&quot;</span>
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> itertools
<a name="l00004"></a>00004 <span class="keyword">from</span> numpy <span class="keyword">import</span> floor, empty, sum <span class="keyword">as</span> npsum
<a name="l00005"></a>00005 <span class="keyword">from</span> numpy <span class="keyword">import</span> asarray, zeros, meshgrid
<a name="l00006"></a>00006 <span class="keyword">from</span> numpy.linalg <span class="keyword">import</span> solve
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="keyword">from</span> SecondOrderStatic1D <span class="keyword">import</span> SecondOrderStatic1D
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 
<a name="l00011"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html">00011</a> <span class="keyword">class </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html">PIDEStatic1D</a>(SecondOrderStatic1D):
<a name="l00012"></a>00012 
<a name="l00013"></a>00013     <span class="stringliteral">&quot;&quot;&quot; Solve the boundary value problem. &quot;&quot;&quot;</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015     __slots__ = [<span class="stringliteral">&#39;m_jumpma&#39;</span>, <span class="stringliteral">&#39;m_pide_bop&#39;</span>, <span class="stringliteral">&#39;m_kernel&#39;</span>, <span class="stringliteral">&#39;m_lambda&#39;</span>]
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 
<a name="l00018"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a2cc77ece8145d14b906252785303aaa7">00018</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a2cc77ece8145d14b906252785303aaa7">__init__</a>(self, nsegs, xleft, xright):
<a name="l00019"></a>00019         <span class="stringliteral">&quot;&quot;&quot; Instantiate an object of partial integro differential type.&quot;&quot;&quot;</span>
<a name="l00020"></a>00020 
<a name="l00021"></a>00021         SecondOrderStatic1D.__init__(self, nsegs, xleft, xright)
<a name="l00022"></a>00022         (self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a>, self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00023"></a>00023         (self.m_pide_bop, self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a>) = (<span class="keywordtype">None</span>, <span class="keywordtype">None</span>)
<a name="l00024"></a>00024 
<a name="l00025"></a>00025     <span class="keyword">def </span>__assemble_jump(self):
<a name="l00026"></a>00026         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00027"></a>00027 <span class="stringliteral">        Info: Use quadrature formulas to assemble jump matrix.</span>
<a name="l00028"></a>00028 <span class="stringliteral">        Output: jump matrix and boundary coefficients.</span>
<a name="l00029"></a>00029 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031         <span class="comment"># get shape function and quad points.</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033         quad_formula = self.get_quads()
<a name="l00034"></a>00034         quadp = quad_formula.get_qpoints()
<a name="l00035"></a>00035 
<a name="l00036"></a>00036         <span class="comment"># evaluate at quad points.</span>
<a name="l00037"></a>00037 
<a name="l00038"></a>00038         sh_funct = self.get_sfunc()
<a name="l00039"></a>00039         shfu_at_quadp = sh_funct.values(quadp)
<a name="l00040"></a>00040 
<a name="l00041"></a>00041         <span class="comment"># Multiply pointwise shape functions at quad.</span>
<a name="l00042"></a>00042 
<a name="l00043"></a>00043         phiijs = []
<a name="l00044"></a>00044         lc_dof = sh_funct.dof()
<a name="l00045"></a>00045         <span class="keywordflow">for</span> (i, j) <span class="keywordflow">in</span> itertools.product(range(0, lc_dof), range(0,
<a name="l00046"></a>00046                 lc_dof)):
<a name="l00047"></a>00047             (phii, phij) = meshgrid(shfu_at_quadp[i], shfu_at_quadp[j])
<a name="l00048"></a>00048             phiijs.append((phii * phij).flatten())
<a name="l00049"></a>00049 
<a name="l00050"></a>00050         <span class="comment"># Evaluate kernel[:, 0] and kernel[0, :]</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052         grid = self.get_mesh()
<a name="l00053"></a>00053         delta_x = grid.getDx()[0]
<a name="l00054"></a>00054         num_cols = grid.get_nsegs() * (lc_dof - 1) + 1
<a name="l00055"></a>00055 
<a name="l00056"></a>00056         <span class="comment"># assemble jump matrix.</span>
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         jump = zeros((num_cols, num_cols), <span class="stringliteral">&#39;float64&#39;</span>)
<a name="l00059"></a>00059 
<a name="l00060"></a>00060         <span class="keywordflow">for</span> (row, col) <span class="keywordflow">in</span> itertools.product(range(0, num_cols),
<a name="l00061"></a>00061                 range(0, num_cols)):
<a name="l00062"></a>00062             jump[row, col] = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a670e0e3d90018d987bff6c9207aa11d5">__jumpij</a>(row, col, num_cols - 1,
<a name="l00063"></a>00063                     delta_x, phiijs)
<a name="l00064"></a>00064 
<a name="l00065"></a>00065         toe_coeff = zeros((2 * num_cols - 1, 1))
<a name="l00066"></a>00066         toe_coeff[:num_cols] = jump[:, 0][::-1].reshape((num_cols, 1))
<a name="l00067"></a>00067         toe_coeff[num_cols - 1:] = jump[0, :].reshape((num_cols, 1))
<a name="l00068"></a>00068 
<a name="l00069"></a>00069         <span class="keywordflow">return</span> (self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> * jump[1:-1, 1:-1], toe_coeff)
<a name="l00070"></a>00070 
<a name="l00071"></a>00071        <span class="comment"># TODO improve on this matter.</span>
<a name="l00072"></a>00072         <span class="comment"># fill upper diagonal term</span>
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="keywordflow">for</span> col_id <span class="keywordflow">in</span> range(0, num_cols):
<a name="l00075"></a>00075             t_upper = toe_coeff[num_cols - 1 + col_id]
<a name="l00076"></a>00076             <span class="keywordflow">for</span> indx <span class="keywordflow">in</span> range(0, num_cols - col_id):
<a name="l00077"></a>00077                 jump[indx, col_id + indx] = t_upper
<a name="l00078"></a>00078 
<a name="l00079"></a>00079         <span class="comment"># fill lower diagonal terms</span>
<a name="l00080"></a>00080 
<a name="l00081"></a>00081         <span class="keywordflow">for</span> row_id <span class="keywordflow">in</span> range(1, num_cols):
<a name="l00082"></a>00082             t_lower = toe_coeff[num_cols - row_id - 1]
<a name="l00083"></a>00083             <span class="keywordflow">for</span> indx <span class="keywordflow">in</span> range(0, num_cols - row_id):
<a name="l00084"></a>00084                 jump[row_id + indx, indx] = t_lower
<a name="l00085"></a>00085 
<a name="l00086"></a>00086         <span class="keywordflow">return</span> (self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> * jump[1:-1, 1:-1], toe_coeff)
<a name="l00087"></a>00087 
<a name="l00088"></a>00088     <span class="keyword">def </span>__eval_kernel(self, points):
<a name="l00089"></a>00089         <span class="stringliteral">&quot;&quot;&quot; expect (n, 2) vector. &quot;&quot;&quot;</span>
<a name="l00090"></a>00090 
<a name="l00091"></a>00091         <span class="keywordflow">return</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>(points)
<a name="l00092"></a>00092 
<a name="l00093"></a>00093 
<a name="l00094"></a>00094     <span class="keyword">def </span>__jumpij(self, row, col, stop, dx, phiijs):
<a name="l00095"></a>00095         <span class="stringliteral">&quot;&quot;&quot; computest (row, col) coefficient.</span>
<a name="l00096"></a>00096 <span class="stringliteral"></span>
<a name="l00097"></a>00097 <span class="stringliteral">            phiijs ~ list of (n, 1) vectors.</span>
<a name="l00098"></a>00098 <span class="stringliteral">                     it holds the upper diagonal matrix</span>
<a name="l00099"></a>00099 <span class="stringliteral">                     \phi_i\phi_j(qpoints)</span>
<a name="l00100"></a>00100 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00101"></a>00101 
<a name="l00102"></a>00102         <span class="keywordflow">if</span> 0. == self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a>:
<a name="l00103"></a>00103             <span class="keywordflow">return</span> 0.
<a name="l00104"></a>00104 
<a name="l00105"></a>00105         quad_formula = self.get_quads()
<a name="l00106"></a>00106         quadp = dx * quad_formula.get_qpoints() / 2.
<a name="l00107"></a>00107         weights = quad_formula.get_weights()
<a name="l00108"></a>00108 
<a name="l00109"></a>00109         (x_weig, y_weig) = meshgrid(weights, weights)
<a name="l00110"></a>00110         xy_weig = x_weig.flatten() * y_weig.flatten()
<a name="l00111"></a>00111 
<a name="l00112"></a>00112         <span class="comment"># all possible kernel quad points</span>
<a name="l00113"></a>00113 
<a name="l00114"></a>00114         (xcol, ycol) = dx * floor(asarray([row, col]) / 2.)
<a name="l00115"></a>00115         (xcoor, ycoor) = meshgrid(xcol + quadp, ycol + quadp)
<a name="l00116"></a>00116         (xcoor_1, ycoor_1) = (xcoor - dx, ycoor - dx)
<a name="l00117"></a>00117 
<a name="l00118"></a>00118         jump_int = 0
<a name="l00119"></a>00119         kernel_00 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor - ycoor).flatten())
<a name="l00120"></a>00120         <span class="keywordflow">if</span> 0 == row % 2 <span class="keywordflow">and</span> 0 == col % 2:
<a name="l00121"></a>00121             <span class="keywordflow">if</span> row &lt; stop <span class="keywordflow">and</span> col &lt; stop:
<a name="l00122"></a>00122                 jump_int = npsum(kernel_00 * phiijs[0] * xy_weig)
<a name="l00123"></a>00123 
<a name="l00124"></a>00124             <span class="keywordflow">if</span> 0 &lt; row <span class="keywordflow">and</span> col &lt; stop:
<a name="l00125"></a>00125                 kernel_1_0 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor_1 - ycoor).flatten())
<a name="l00126"></a>00126                 jump_int += npsum(kernel_1_0 * phiijs[6] * xy_weig)
<a name="l00127"></a>00127 
<a name="l00128"></a>00128             <span class="keywordflow">if</span> row &lt; stop <span class="keywordflow">and</span> 0 &lt; col:
<a name="l00129"></a>00129                 kernel_0_1 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor - ycoor_1).flatten())
<a name="l00130"></a>00130                 jump_int += npsum(kernel_0_1 * phiijs[2] * xy_weig)
<a name="l00131"></a>00131 
<a name="l00132"></a>00132             <span class="keywordflow">if</span> 0 &lt; row <span class="keywordflow">and</span> 0 &lt; col:
<a name="l00133"></a>00133                 kernel_1_1 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor_1
<a name="l00134"></a>00134                         - ycoor_1).flatten())
<a name="l00135"></a>00135                 jump_int += npsum(kernel_1_1 * phiijs[8] * xy_weig)
<a name="l00136"></a>00136         <span class="keywordflow">elif</span> 1 == row % 2 <span class="keywordflow">and</span> 0 == col % 2:
<a name="l00137"></a>00137             <span class="keywordflow">if</span> col &lt; stop:
<a name="l00138"></a>00138                 jump_int = npsum(kernel_00 * phiijs[3] * xy_weig)
<a name="l00139"></a>00139             <span class="keywordflow">if</span> 0 &lt; col:
<a name="l00140"></a>00140                 kernel_0_1 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor - ycoor_1).flatten())
<a name="l00141"></a>00141                 jump_int += npsum(kernel_0_1 * phiijs[5] * xy_weig)
<a name="l00142"></a>00142         <span class="keywordflow">elif</span> 0 == row % 2 <span class="keywordflow">and</span> 1 == col % 2:
<a name="l00143"></a>00143             <span class="keywordflow">if</span> row &lt; stop:
<a name="l00144"></a>00144                 jump_int = npsum(kernel_00 * phiijs[1] * xy_weig)
<a name="l00145"></a>00145             <span class="keywordflow">if</span> 0 &lt; row:
<a name="l00146"></a>00146                 kernel_1_0 = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>((xcoor_1 - ycoor).flatten())
<a name="l00147"></a>00147                 jump_int += npsum(kernel_1_0 * phiijs[7] * xy_weig)
<a name="l00148"></a>00148         <span class="keywordflow">else</span>:
<a name="l00149"></a>00149             jump_int = npsum(kernel_00 * phiijs[4] * xy_weig)
<a name="l00150"></a>00150 
<a name="l00151"></a>00151         <span class="keywordflow">return</span> dx * dx * jump_int / 4.  <span class="comment"># this basis has support 4.</span>
<a name="l00152"></a>00152 
<a name="l00153"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a4ffdf941fcfcf878737a3fa64284f42d">00153</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a4ffdf941fcfcf878737a3fa64284f42d">get_jump</a>(self):
<a name="l00154"></a>00154         <span class="stringliteral">&quot;&quot;&quot; returns jump matrix in full format. &quot;&quot;&quot;</span>
<a name="l00155"></a>00155 
<a name="l00156"></a>00156         <span class="keywordflow">if</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a> <span class="keywordflow">is</span> <span class="keywordtype">None</span>:
<a name="l00157"></a>00157             (self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a>, self.m_pide_bop) = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a1c76a2c77559ead5392aa402c1555b9e">__assemble_jump</a>()
<a name="l00158"></a>00158         <span class="keywordflow">return</span> (self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a>, self.m_pide_bop)
<a name="l00159"></a>00159 
<a name="l00160"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a75e6704da7dc0f1603859e348e6c387e">00160</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a75e6704da7dc0f1603859e348e6c387e">get_lambda</a>(self):
<a name="l00161"></a>00161         <span class="stringliteral">&quot;&quot;&quot; return jump intensity. &quot;&quot;&quot;</span>
<a name="l00162"></a>00162 
<a name="l00163"></a>00163         <span class="keywordflow">return</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a>
<a name="l00164"></a>00164 
<a name="l00165"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a98a51f911e13033d77cb6ee38a09816d">00165</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a98a51f911e13033d77cb6ee38a09816d">get_pde</a>(self):  <span class="comment"># PDE contribution</span>
<a name="l00166"></a>00166         <span class="stringliteral">&quot;&quot;&quot; pde matrix is sparse format. &quot;&quot;&quot;</span>
<a name="l00167"></a>00167 
<a name="l00168"></a>00168         <span class="keywordflow">return</span> self.get_stiff_dformat()  <span class="comment"># PDE contribution</span>
<a name="l00169"></a>00169 
<a name="l00170"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a948d29230be999b6bc9a002f233daec0">00170</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a948d29230be999b6bc9a002f233daec0">get_mass</a>(self):  <span class="comment"># Time step discretization.</span>
<a name="l00171"></a>00171         <span class="stringliteral">&quot;&quot;&quot; mass matrix is sparse format. &quot;&quot;&quot;</span>
<a name="l00172"></a>00172 
<a name="l00173"></a>00173         <span class="keywordflow">return</span> self.get_mass_dformat()
<a name="l00174"></a>00174 
<a name="l00175"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#ad5d21dbdc5b9de8ed4a1d5c92524c6c2">00175</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#ad5d21dbdc5b9de8ed4a1d5c92524c6c2">reset</a>(self):
<a name="l00176"></a>00176         <span class="stringliteral">&quot;&quot;&quot;</span>
<a name="l00177"></a>00177 <span class="stringliteral">            Free memory and set local variables to None.</span>
<a name="l00178"></a>00178 <span class="stringliteral">        &quot;&quot;&quot;</span>
<a name="l00179"></a>00179 
<a name="l00180"></a>00180         <span class="keywordflow">if</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00181"></a>00181             del self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a>
<a name="l00182"></a>00182             self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> = <span class="keywordtype">None</span>
<a name="l00183"></a>00183 
<a name="l00184"></a>00184         <span class="keywordflow">if</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a> <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00185"></a>00185             del self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a>
<a name="l00186"></a>00186             self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a> = <span class="keywordtype">None</span>
<a name="l00187"></a>00187 
<a name="l00188"></a>00188         <span class="keywordflow">if</span> self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a> <span class="keywordflow">is</span> <span class="keywordflow">not</span> <span class="keywordtype">None</span>:
<a name="l00189"></a>00189             del self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a>
<a name="l00190"></a>00190             self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#afc26f1e55f89df3eb593d1d47c207313">m_jumpma</a> = <span class="keywordtype">None</span>
<a name="l00191"></a>00191 
<a name="l00192"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a48e49c42bc31792a059bc470d3f5b8e0">00192</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a48e49c42bc31792a059bc470d3f5b8e0">set_pide_cos</a>(self, diff, conv, reac, lamb):
<a name="l00193"></a>00193         <span class="stringliteral">&quot;&quot;&quot; diffusion, convection, reaction,  jump  &quot;&quot;&quot;</span>
<a name="l00194"></a>00194 
<a name="l00195"></a>00195         super(PIDEStatic1D, self).<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#ada37a3b95d1c8c0f5d925fd5bd30a355">set_cos</a>(diff, conv, reac - lamb)
<a name="l00196"></a>00196         self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> = lamb
<a name="l00197"></a>00197 
<a name="l00198"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#ada37a3b95d1c8c0f5d925fd5bd30a355">00198</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#ada37a3b95d1c8c0f5d925fd5bd30a355">set_cos</a>(self, diff, conv, reac, d_is_real=True,
<a name="l00199"></a>00199             c_is_real=<span class="keyword">True</span>, r_is_real=<span class="keyword">True</span>):
<a name="l00200"></a>00200         <span class="stringliteral">&quot;&quot;&quot; make sure that the pde interface does not get called when</span>
<a name="l00201"></a>00201 <span class="stringliteral">            solving a pide equation. &quot;&quot;&quot;</span>
<a name="l00202"></a>00202 
<a name="l00203"></a>00203         <span class="keywordflow">raise</span> NotImplementedError, \
<a name="l00204"></a>00204             <span class="stringliteral">&#39;use set_pide_cos to set PIDE params.&#39;</span>
<a name="l00205"></a>00205 
<a name="l00206"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a409795a5353a99288895c3431581d350">00206</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a409795a5353a99288895c3431581d350">set_kernel</a>(self, kernel):
<a name="l00207"></a>00207         <span class="stringliteral">&quot;&quot;&quot; user define kernel. &quot;&quot;&quot;</span>
<a name="l00208"></a>00208 
<a name="l00209"></a>00209         self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a0d0b5924af4c7b3b00923f5cc07f4e13">m_kernel</a> = kernel
<a name="l00210"></a>00210 
<a name="l00211"></a><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#abfd7b75e1deeee3d8c3cd3c41524b174">00211</a>     <span class="keyword">def </span><a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#abfd7b75e1deeee3d8c3cd3c41524b174">solve</a>(self):
<a name="l00212"></a>00212         <span class="stringliteral">&quot;&quot;&quot; solve the boundary value problem &quot;&quot;&quot;</span>
<a name="l00213"></a>00213 
<a name="l00214"></a>00214         <span class="comment"># Jump matrix and boundary operator.</span>
<a name="l00215"></a>00215 
<a name="l00216"></a>00216         (pide_mat, pide_bop) = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a1c76a2c77559ead5392aa402c1555b9e">__assemble_jump</a>()
<a name="l00217"></a>00217 
<a name="l00218"></a>00218         <span class="comment"># Add PDE contribution.</span>
<a name="l00219"></a>00219 
<a name="l00220"></a>00220         stiff_diag = self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a98a51f911e13033d77cb6ee38a09816d">get_pde</a>()  <span class="comment"># PDE contribution</span>
<a name="l00221"></a>00221 
<a name="l00222"></a>00222         <span class="keywordflow">for</span> (posi, val) <span class="keywordflow">in</span> enumerate(stiff_diag[1:-1, 0]):
<a name="l00223"></a>00223             pide_mat[posi, posi] += val
<a name="l00224"></a>00224 
<a name="l00225"></a>00225         <span class="keywordflow">for</span> (posi, val) <span class="keywordflow">in</span> enumerate(stiff_diag[2:-1, 1]):
<a name="l00226"></a>00226             pide_mat[posi, posi + 1] += val
<a name="l00227"></a>00227 
<a name="l00228"></a>00228         <span class="keywordflow">for</span> (posi, val) <span class="keywordflow">in</span> enumerate(stiff_diag[1:-2, 2]):
<a name="l00229"></a>00229             pide_mat[posi + 1, posi] += val
<a name="l00230"></a>00230 
<a name="l00231"></a>00231         <span class="keywordflow">if</span> 3 == self.get_sfunc().dof():
<a name="l00232"></a>00232             <span class="keywordflow">for</span> (posi, val) <span class="keywordflow">in</span> enumerate(stiff_diag[3:-1, 3]):
<a name="l00233"></a>00233                 pide_mat[posi, posi + 2] += val
<a name="l00234"></a>00234 
<a name="l00235"></a>00235             <span class="keywordflow">for</span> (posi, val) <span class="keywordflow">in</span> enumerate(stiff_diag[1:-3, 4]):
<a name="l00236"></a>00236                 pide_mat[posi + 2, posi] += val
<a name="l00237"></a>00237 
<a name="l00238"></a>00238         (uleft, uright) = self.get_bd_conditions()
<a name="l00239"></a>00239         rhs = self.get_load_terms()
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         <span class="comment"># Complement RHS with jump contribution.</span>
<a name="l00242"></a>00242 
<a name="l00243"></a>00243         left_jump = pide_bop[:rhs.size]
<a name="l00244"></a>00244         right_jump = pide_bop[-rhs.size:]
<a name="l00245"></a>00245         rhs -= self.<a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#a9610bb0b96cdacaac0e2e8f8468e11a1">m_lambda</a> * (uleft * left_jump + uright
<a name="l00246"></a>00246                                 * right_jump)[::-1]
<a name="l00247"></a>00247 
<a name="l00248"></a>00248         <span class="comment"># Complement RHS with PDE contribution.</span>
<a name="l00249"></a>00249 
<a name="l00250"></a>00250         <span class="keywordflow">if</span> 3 == self.get_sfunc().dof():
<a name="l00251"></a>00251             rhs[2] -= uleft * stiff_diag[0, 4]
<a name="l00252"></a>00252             rhs[-3] -= uright * stiff_diag[-1, 3]
<a name="l00253"></a>00253 
<a name="l00254"></a>00254         rhs[1] -= uleft * stiff_diag[0, 2]
<a name="l00255"></a>00255         rhs[-2] -= uright * stiff_diag[-1, 1]
<a name="l00256"></a>00256 
<a name="l00257"></a>00257         load = rhs[1:-1]
<a name="l00258"></a>00258 
<a name="l00259"></a>00259         <span class="comment"># Solve the system of equations.</span>
<a name="l00260"></a>00260 
<a name="l00261"></a>00261         solu = empty((rhs.size, 1))
<a name="l00262"></a>00262         solu[1:-1] = <a class="code" href="classmodels_1_1PIDEStatic1D_1_1PIDEStatic1D.html#abfd7b75e1deeee3d8c3cd3c41524b174">solve</a>(pide_mat, load).reshape((load.size, 1))
<a name="l00263"></a>00263         (solu[0], solu[-1]) = (uleft, uright)
<a name="l00264"></a>00264         <span class="keywordflow">return</span> solu
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Dec 22 2011 05:17:53 for OptionsPricing by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
